///PHILOTES Source Code.  (C)2012 PhiloLabs
#pragma once

#ifndef __Polygon_H__
#define __Polygon_H__

#include "OgrePrerequisites.h"
#include "math/vector3.h"


namespace Ogre
{

	class _OgreExport Polygon
	{

	public:
		typedef vector<Vector3>::type				VertexList;

		typedef multimap<Vector3, Vector3>::type		EdgeMap;
		typedef std::pair< Vector3, Vector3>		Edge;

	protected:
		VertexList			mVertexList;
		mutable Vector3	mNormal;
		mutable bool		mIsNormalSet;
		
		void updateNormal(void) const;


	public:
		Polygon();
		~Polygon();
		Polygon( const Polygon& cpy );

		
		void insertVertex(const Vector3& vdata, size_t vertexIndex);
		
		void insertVertex(const Vector3& vdata);

		
		const Vector3& getVertex(size_t vertex) const;

		
		void setVertex(const Vector3& vdata, size_t vertexIndex);

		
		void removeDuplicates(void);

		
		size_t getVertexCount(void) const;

		
		const Vector3& getNormal(void) const;

		
		void deleteVertex(size_t vertex);

		
		bool isPointInside(const Vector3& point) const;

		
		void storeEdges(EdgeMap *edgeMap) const;

		
		void reset(void);

		
		bool operator == (const Polygon& rhs) const;

		
		bool operator != (const Polygon& rhs) const
		{ return !( *this == rhs ); }

		
		_OgreExport friend std::ostream& operator<< ( std::ostream& strm, const Polygon& poly );

	};
	
}

#endif
